/*
 * Copyright (c) 2017-2019, Lindenis Tech. Ltd.
 * All rights reserved.
 *
 * File:
 *
 * Description:
 *
 * Author:
 *      xiaoshujun@lindeni.com
 *
 * Create Date:
 *      2019/08/08
 *
 * History:
 *
 */

#ifndef __LINDENI_ES_PLYAER__
#define __LINDENI_ES_PLYAER__

#ifdef __cplusplus
extern "C" {
#endif

#include "lindcomponent.h"
#include "lindplayer.h"

#define es_player_handle_t  _handle_t

/**
 * cb: callback function called by player framework.
 * user: who will response the callback funtion.
 */
typedef struct _lindesplayer_config_t
{
    lindplayer_cb   cb;
    void *          user;

    /*
     * display postion: [x, y, w, h].
     */
    rect_t          disp_pos;

    /*
     * display rotate degree.
     */
    rotate_degree_e rotate;

    av_enc_type_t   venc_type;

    /*
     * the layer z-order
     *  range [0, 16]: from bottom to up
     */
    int             z_order;

    /*
     * channel id: 0 or 1
     *  0. Display engine has 2 video channels.
     *  1. Each video channel has 4 layers.
     *  2. All layers in the same channel must be the same attribution('format', 'size', 'scale ratio')
     *  3. Layers in different channel can be different attribution.
     *  4. Upto 4 different layers with the same resolution can be in the same channel.
     *  5. Layers with the different resolution must be in the different channel.
     */
    int             channel_id;
} lindesplayer_config_t;

/**
 * usally an es player will be called like this:
 *    step 1: call player_create()
 *        to create a player.
 *    step 2: call esplayer_set_parameters()
 *        to set callback function to monitor some message from the palyer framework.
 *        to set some other parameters to the player which can be used for playing.
 *    step 3: call esplayer_prepare()
 *        to let the player ready to play.
 *    step 4: call player_send_es()
 *        to send es to the player, the player will decode and render.
 *    step 5: call player_destroy()
 *        before exit the player.
 */

/**
 * create a player object.
 * @param
 * @return
 *    NULL: create player failed.
 *    others: a player handle.
 */
_handle_t esplayer_create();

/**
 * call player_destroy to destroy the player before exit the app.
 *
 * @param
 *    h_player[in]: player handle
 * @return
 */
void esplayer_destroy(_handle_t h_player);

/**
 * app set some parameters to the player which can be used for playing.
 * Or app change some parameters while playing.
 *
 * @param
 *    h_player[in]: player handle
 *    p_config[in]: parameter for playing control.
 * @return
 *    0 success, -1 error
 */
int esplayer_set_parameters(_handle_t h_player, lindesplayer_config_t * p_config);

/**
 * app get parameters.
 *
 * @param
 *    h_player[in]: player handle
 *    p_config[in]: only use callback parameter for notify message.
 * @return
 *    0 success, -1 error
 */
int esplayer_get_parameters(_handle_t h_player, lindesplayer_config_t * p_config);

/**
 * let the player prepare to play.
 *
 * @param
 *    h_player[in]: player handle
 * @return
 *    0 success, -1 error
 */
int esplayer_prepare(_handle_t h_player);

/**
 * 1. send es to the player.
 * 2. request video frame decoded and render it.
 *
 * @param
 *    h_player[in]  : player handle
 *    data[in]      : h264 element stream
 *    size[in]      : lenght in Bytes of 'data'
 * @return
 *    0 success, -1 error
 */
int esplayer_decode_es(_handle_t h_player, void * data, int size);
#define esplayer_send_es esplayer_decode_es

/**
 * set a black frame to display.
 *
 * @param
 *    h_player[in]: player handle
 * @return
 *    0 success, -1 error
 */
int esplayer_set_black_frame(_handle_t h_player);

/**
 * Display use a pre-alloced pmem for all esplayers.
 * Independent of any player.
 *
 * @param
 *    num [in]: pmem number
 *    size[in]: size of each pmem
 * @return
 *    0 success, -1 error
 */
int esplayer_init_reserved_mem(size_t num, size_t size);
void esplayer_deinit_reserved_mem();

#ifdef __cplusplus
}
#endif

#endif	// __LINDENI_ES_PLYAER__

